/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package forumgui;

import TamirsGui.GuiMessage;
import java.util.Vector;

/**
 *
 * @author Roy
 */
public class ModeratorWindow extends javax.swing.JDialog {

    /**
     * Creates new form ModeratorWindow
     */
    public ModeratorWindow(java.awt.Frame parent, boolean modal,GuiMessage.MessageSubType subType,Vector<GuiMessage>msgs) {
        super(parent, modal);
        initComponents();
        switch (subType)
        {
            case candidateList:
                this.removeModeratorButton.setVisible(false);
                this.statisticButton.setVisible(false);
                this.changeAdminButton.setVisible(false);
                break;
            case moderatorList:
                this.addModeratorButton.setVisible(false);
                this.statisticButton.setVisible(false);
                this.changeAdminButton.setVisible(false);
                break;
            case usersList:
                this.removeModeratorButton.setVisible(false);
                this.addModeratorButton.setVisible(false);
                this.changeAdminButton.setVisible(false);
                break;
            case adminList:
                this.removeModeratorButton.setVisible(false);
                this.addModeratorButton.setVisible(false);
                this.statisticButton.setVisible(false);
        }
        this.msgsList = msgs;
        this.msgsJlist.setListData(msgs);
        selectedOne = "";
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        msgsJlist = new javax.swing.JList();
        addModeratorButton = new javax.swing.JButton();
        removeModeratorButton = new javax.swing.JButton();
        statisticButton = new javax.swing.JToggleButton();
        changeAdminButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);

        msgsJlist.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(msgsJlist);

        addModeratorButton.setText("add moderator");
        addModeratorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addModeratorButtonActionPerformed(evt);
            }
        });

        removeModeratorButton.setText("remove Moderator");
        removeModeratorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeModeratorButtonActionPerformed(evt);
            }
        });

        statisticButton.setText("get statistic");
        statisticButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                statisticButtonActionPerformed(evt);
            }
        });

        changeAdminButton.setText("change Admin");
        changeAdminButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeAdminButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addModeratorButton)
                        .addGap(17, 17, 17)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(changeAdminButton)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(removeModeratorButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
                                .addComponent(statisticButton)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addModeratorButton)
                    .addComponent(removeModeratorButton)
                    .addComponent(statisticButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(changeAdminButton)
                .addGap(29, 29, 29))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addModeratorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addModeratorButtonActionPerformed
        addOrRemoveModeartor();
    }//GEN-LAST:event_addModeratorButtonActionPerformed

    private void removeModeratorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeModeratorButtonActionPerformed
        addOrRemoveModeartor();
    }//GEN-LAST:event_removeModeratorButtonActionPerformed

    private void statisticButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_statisticButtonActionPerformed
         addOrRemoveModeartor();
    }//GEN-LAST:event_statisticButtonActionPerformed

    private void changeAdminButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeAdminButtonActionPerformed
        addOrRemoveModeartor();
    }//GEN-LAST:event_changeAdminButtonActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addModeratorButton;
    private javax.swing.JButton changeAdminButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList msgsJlist;
    private javax.swing.JButton removeModeratorButton;
    private javax.swing.JToggleButton statisticButton;
    // End of variables declaration//GEN-END:variables

    public String getSelectedOne() {
        return selectedOne;
    }
    private GuiMessage msg;
    private Vector<GuiMessage> msgsList;
    private String selectedOne;
    private void addOrRemoveModeartor() {
        msg = (GuiMessage)this.msgsJlist.getSelectedValue();
        if (msg != null)
        {
            selectedOne = msg.getTitle();
            this.setVisible(false);
        }
    }
   
}
